<?php
include("../../tools/session.php");
include("../../tools/controls.php");

// 如果登录失败、无权限访问，那么采取相应措施
if (!($is_login_success === true)) { session_hop_page("../index.php"); exit(); }
if (!power_check(0)) { include("tpl-inc-wp.php"); $tpl->display($oa_tpl_path . "/no-power.html"); exit(); }

/*-- 以下是实际内容 --*/
$page_status = $_POST["page_status"];
// $page_status = $_GET["page_status"];

// 如果状态 $page_status 为空，那么载入默认页面
if (!$page_status)
{
    include("tpl-inc-wp.php");
    $tpl->display($oa_tpl_path . "/default/new_application.html");
}
// 如果状态为 1，那么输出解析公文模板后的 XML 页面
elseif ($page_status == 1)
{
    include("../../tools/mysql.php");
    db_connect();
    
    header("content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    echo "<doctpl>\n";

    $sql = "SELECT * FROM view_doc_tpl";
    $re = db_query($sql);

    $tpls = array();
    foreach ($re as $v)
    {
	if (!$tpls[$v["tpl_class_id"]]) { $tpls[$v["tpl_class_id"]] = array(); }
	$tpls[$v["tpl_class_id"]][] = $v;
    }
    
    foreach ($tpls as $v)
    {
	echo "<class name=\"" . $v[0]["zh_name"] . "\">\n";
	foreach ($v as $t)
	{
	    echo "<item>\n";
	    echo "<id>" . $t["tpl_id"] . "</id>\n";
	    echo "<name>" . $t["name"] . "</name>\n";
	    echo "<type>" . $t["type"] . "</type>\n";
	    echo "<pic><![CDATA[" . $t["pic"] . "]]></pic>\n";
	    echo "<author>" . $t["author"] . "</author>\n";
	    echo "<ctime>" . $t["create_time"] . "</ctime>\n";
	    // echo "<template><![CDATA[" . $t["template"] . "]]></template>";
	    echo "</item>\n";
	}
	echo "</class>";
    }
    
    echo "</doctpl>\n";
}
?>
